home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-18 | 3.6 KB | 160 lines |
- /*
- * @(#)ServletServer.java 1.7 97/07/17
- *
- * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This software is the confidential and proprietary information of Sun
- * Microsystems, Inc. ("Confidential Information"). You shall not
- * disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Sun.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
- * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- * CopyrightVersion 1.0
- */
-
- package sun.servlet.isapi;
-
- import java.io.*;
- import java.util.*;
- import javax.servlet.Servlet;
- import sun.servlet.*;
- import sun.servlet.http.*;
- import sun.servlet.util.*;
-
- /**
- * This class implements servlet runner for Microsoft Information Server
- *
- * @version 1.7, 07/17/97
- * @author Jongyoon Lee
- */
- public class ServletServer extends HttpServer {
-
- /**
- * The server instance.
- */
- protected static ServletServer server;
-
- /*
- * The loaded classes.
- */
- private Hashtable classes = new Hashtable();
-
- /*
- * The loaded servlets.
- */
- private Hashtable servlets = new Hashtable();
-
- /**
- * Runs the HTTP server.
- */
- public static void main(String args[]) {
- Properties prop = new Properties();
- server = new ServletServer();
- for (int i = 0; i < args.length; i++) {
- int index = args[i].indexOf('=');
- if (index != -1) {
- prop.put(args[i].substring(0, index),
- args[i].substring(index + 1));
- }
- }
- server.loadProperties(prop);
- server.run();
-
- /*
- } catch (Exception e) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- e.printStackTrace(ps);
- byte[] buf = baos.toByteArray();
- return new String(buf);
- }
- return "FOO";
- */
- }
-
- /**
- * Runs the servlet runner
- */
- public void run() {
- try {
- System.loadLibrary("servlet");
- } catch (Exception e) {
- System.exit(0);
- }
-
- handlers = new ThreadGroup("ServletServer-");
-
- // initialize connection handlers
- connections = new Queue(maxHandlers);
- total = 0;
- avail = 0;
- }
-
- /**
- * Accepts a new connection
- */
- public static void handleConnection(long ecb) {
- server.newConnection(ecb);
- }
-
- private void newConnection(long ecb) {
- //try {
-
- ISAPIConnectionHandler handler = new ISAPIConnectionHandler(this);
- handler.init(ecb);
- handler.run();
-
- /*
- } catch (Exception e) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- e.printStackTrace(ps);
- byte[] buf = baos.toByteArray();
- return new String(buf);
- }
- return "GOOD!";
- */
- }
-
-
- /**
- * Gets a servlet by name.
- */
- public Servlet getServlet(String name) {
- String code = servletProps.getProperty("servlet." +
- name +
- ".code");
- String args = servletProps.getProperty("servlet." +
- name +
- ".initArgs");
- if (code == null) {
- code = name;
- }
-
- Servlet s = (Servlet) servlets.get(code);
- if (s != null) {
- return s;
- }
- try {
- Class cl = Class.forName(code);
- //Class cl = Class.forName("SnoopServlet");
- if (cl != null) {
- s = (Servlet) cl.newInstance();
- s.init(new HttpServletConfig(this, args));
- servlets.put(name, s);
- }
- } catch (Throwable e) {
- return null;
- }
-
- return s;
- }
- }
-